package com.haq.housesystem.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.haq.housesystem.bean.Houses;
import com.haq.housesystem.dao.HousesDao;
import com.haq.housesystem.service.HousesService;
@Service
@Transactional
public class HousesServiceImpl implements HousesService {
    @Autowired
    HousesDao houseDao;
    public void insert(Houses houses) {
        houseDao.insert(houses);

    }

    public void update(Houses houses) {
        houseDao.update(houses);

    }

    public void delete(int houseId) {
        houseDao.delete(houseId);

    }

    public void deleteByIds(int[] houseIds) {
        houseDao.deleteByIds(houseIds);

    }

    public List<Houses> selectAll() {
        List<Houses> list = houseDao.selectAll();
        return list;
    }

    public Houses selectById(int houseId) {
        Houses house = houseDao.selectById(houseId);
        return house;
    }

    public List<Houses> selectByTitleTypeOrientState(String title, int typeId, int orientId, int houseState) {
        Map map=new HashMap();
        map.put("title", title);
        map.put("typeId", typeId);
        map.put("orientId", orientId);
        map.put("houseState", houseState);


        List<Houses> list = houseDao.selectByTitleTypeOrientState(map);
        return list;
    }

    public PageInfo<Houses> selectAllByPageInfo(int curPage, int size) {
        PageHelper.startPage(curPage, size);
        List<Houses> list = houseDao.selectAll();
        PageInfo<Houses> pageInfo=new PageInfo<Houses>(list);
        return pageInfo;
    }

    public PageInfo<Houses> selectAllByTitleTypeOrientStateByPageInfo(int curPage, int size, String title, int typeId,
                                                                   int orientId, int houseState) {
        PageHelper.startPage(curPage, size);
        Map map=new HashMap();
        map.put("title", title);
        map.put("typeId", typeId);
        map.put("orientId", orientId);
        map.put("houseState", houseState);
        List<Houses> list = houseDao.selectByTitleTypeOrientState(map);
        PageInfo<Houses> pageInfo=new PageInfo<Houses>(list);
        return pageInfo;
    }
}

